﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gonte.Desktop
{
    /// <summary>
    /// SSO for the desktop
    /// </summary>
    public class ApplicationUser
    {
        #region Properties

        /// <summary>
        /// The id of the user
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// The logon name
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// The user password
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// The applications the user have access to
        /// </summary>
        public IList<Application> Applications { get; set; }

        /// <summary>
        /// The current selected application
        /// </summary>
        public Application SelectedApplication { get; set; }

        #endregion

        #region Methods

        public static ApplicationUser LogOn(string userName, string password)
        {
            // Get the user id
            // With that user id go to the membership table and retrieve the application(s) that belong to that user

            // if not found return null;

            ApplicationUser user =  new ApplicationUser
            {
                UserName = userName,
                // Do not set the password,
                Applications = new List<Application>
                {
                    new Application
                    {
                        Name = "Application 1"  
                    },
                    new Application
                    {
                        Name = "Application 2"  
                    }
                }
            };

            // Set the current application if the number of available applications is one
            if (user.Applications.Count == 1)
            {
                user.SelectedApplication = user.Applications[0];
            }

            return user;
        }

        #endregion
    }
}
